package com.sac.common.utils;

import com.sac.system.domain.UserDO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import java.security.Principal;
import java.util.Collection;
import java.util.List;

public class ShiroUtils {
    @Autowired
    private static SessionDAO sessionDAO;


    public static Subject getSubjct() {
        return SecurityUtils.getSubject();
    }

    public static UserDO getUser() {
        /*Object object = getSubjct().getPrincipal();
        UserDao userMapper = ApplicationContextRegister.getBean(UserDao.class);

        return userMapper.get(Long.parseLong(object.toString()));*/
        return (UserDO)SecurityUtils.getSubject().getSession().getAttribute("currentUser");
    }

    public static String getEmpId() {
        return getUser().getEmpId();
    }
    public static void logout() {
        getSubjct().logout();
    }

    public static List<Principal> getPrinciples() {
        List<Principal> principals = null;
        Collection<Session> sessions = sessionDAO.getActiveSessions();
        return principals;
    }

}
